"use client";
import React, { useEffect } from "react";
import {
    Button,
    DatePicker,
    Form,
    Input,
    Select,
} from "antd";

interface Iprops {
    title: string;
    objs: object;
    handleOk: () => void;
    shuju: () => void;
}
import * as API from '../../api/http'
const Formlist = (props: Iprops) => {
    const [form] = Form.useForm();
    // 数据回显
    useEffect(() => {
        form.setFieldsValue(props.objs);
    }, []);
  // 添加与编辑
    const onFinish = async(values:any) => {
    if(props.title=='添加'){
        let t=Date.now()
        let obj={
            ...values,
            id:t
        }
        await API.addlist(obj)
        props.handleOk()
        props.shuju()
    }else{
        let obj={
            ...props.objs,
            ...values
        }
        await API.editlist(obj)
        props.handleOk()
        props.shuju()
    }
};
return (
    <Form form={form}  onFinish={onFinish}>
        <Form.Item label="订单编号" name="key">
            <Input />
        </Form.Item>
        <Form.Item label="订单标题" name="title">
            <Input />
        </Form.Item>
        <Form.Item label="关联客户" name="name">
            <Input />
        </Form.Item>
        <Form.Item label="订单总金额" name="money">
            <Input />
        </Form.Item>
        <Form.Item label="审批类型" name="type">
            <Select>
                <Select.Option value="等待审批">等待审批</Select.Option>
                <Select.Option value="审批通过">审批通过</Select.Option>
                <Select.Option value="审批否决">审批否决</Select.Option>
                <Select.Option value="驳回审批">驳回审批</Select.Option>
            </Select>
        </Form.Item>
        <Form.Item label="创建人员" name="ren">
            <Input />
        </Form.Item>
        <Form.Item label="创建时间" name="time">
            <DatePicker />
        </Form.Item>
        <Form.Item>
            <Button type="primary" htmlType="submit">提交</Button>
        </Form.Item>
    </Form>
);
};

export default Formlist;
